home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / FLOPTST.ASM < prev    next >
Assembly Source File  |  1991-09-23  |  10KB  |  237 lines

  1. ; File......: FLOPTST.ASM
  2. ; Author....: Joseph LaCour
  3. ; Date......: $Date:   23 Sep 1991 14:56:42  $
  4. ; Revision..: $Revision:   1.3  $
  5. ; Log file..: $Logfile:   E:/nanfor/src/floptst.asv  $
  6. ; This is an original work by Joseph LaCour and is placed in the
  7. ; public domain.
  8. ;
  9. ;
  10. ;  ACKNOWLEDGEMENTS:
  11. ;
  12. ;          PAOLO RAMOZZI FOR HIS WORK IN DBDCHECK FOR SHOWING HOW TO
  13. ;          USE INT 13H.
  14. ;
  15. ;
  16. ; Modification history:
  17. ; ---------------------
  18. ;
  19. ; $Log:   E:/nanfor/src/floptst.asv  $
  20. ;  
  21. ;     Rev 1.3   23 Sep 1991 14:56:42   GLENN
  22. ;  Bug reports from Craig Austin, James Finnal, and Ted Means.  Line 128
  23. ;  had MOV FDRIVE,AL which should have been MOV FDRIVE,BL.  This caused the
  24. ;  function to erroneously use the last drive available instead of the one
  25. ;  specified by the calling process.
  26. ;  
  27. ;     Rev 1.2   15 Aug 1991 23:07:48   GLENN
  28. ;  Forest Belt proofread/edited/cleaned up doc
  29. ;  
  30. ;     Rev 1.1   11 May 1991 00:21:42   GLENN
  31. ;  File header changed to conform to Toolkit standard.
  32. ;
  33.  
  34. ;  $DOC$
  35. ;  $FUNCNAME$
  36. ;      FT_FLOPTST()
  37. ;  $CATEGORY$
  38. ;      DOS/BIOS
  39. ;  $ONELINER$
  40. ;      Test diskette drive status
  41. ;  $SYNTAX$
  42. ;      FT_FLOPTST( <nDrive> ) -> nStatus
  43. ;  $ARGUMENTS$
  44. ;      <nDrive> is the diskette drive number, 0 = A:, 1 = B:
  45. ;  $RETURNS$  
  46. ;      -1 - Wrong Parameters
  47. ;       0 - Drive Loaded and ready to read or write
  48. ;       1 - Drive Door Open or Diskette inserted upside down
  49. ;       2 - Diskette is unformatted
  50. ;       3 - Write protected
  51. ;       4 - Undetermined
  52. ;  $DESCRIPTION$
  53. ;      FT_FLOPTST() is designed as a full replacement for ISDRIVE().  Where
  54. ;      ISDRIVE() returns just .T. or .F. depending if the diskette drive is
  55. ;      ready or not, FT_FLOPTST() returns a numeric code designating the
  56. ;      diskette drive's status.
  57. ;
  58. ;      FT_FLOPTST() is particularly useful in backup and restore programs
  59. ;      that need to test the floppy drive before writing/reading from a
  60. ;      floppy disk.
  61. ;  $EXAMPLES$
  62. ;      iStatus := FT_FLOPTST( 1 )
  63.  
  64. ;      DO CASE
  65. ;         CASE iStatus == 1
  66. ;            Qout( "The door to drive A is open." )
  67. ;         CASE iStatus == 2
  68. ;            Qout( "The diskette in drive A is not formatted." )
  69. ;         CASE iStatus == 3
  70. ;            Qout( "The diskette in drive A is write-protected." )
  71. ;         CASE iStatus == 4
  72. ;            Qout( "Something is wrong with drive A, but I don't know what." )
  73. ;      ENDCASE
  74. ;  $END$
  75.  
  76.  
  77. public  FT_FLOPTST
  78.  
  79. EXTRN   __PARNI:FAR
  80. EXTRN   __PARINFO:FAR
  81. EXTRN   __RETNI:FAR
  82.  
  83. _FT_DATASEG  SEGMENT PUBLIC  'DATA'
  84.  
  85. FDRIVE          DB      0
  86. BOOT_SECT       DB      512 DUP (0)
  87.  
  88. _FT_DATASEG  ENDS
  89.  
  90. _NANFOR   SEGMENT 'CODE'
  91.         ASSUME  CS:_NANFOR,DS:_FT_DATASEG,ES:_FT_DATASEG,SS:NOTHING
  92.  
  93.  
  94. FT_FLOPTST      PROC    FAR
  95.  
  96.                 XOR     AX,AX                        ; GET # OF PARAMETERS
  97.                 PUSH    AX                           ;
  98.                 CALL    __PARINFO                    ; CALL INFORMATION FUNCTION
  99.                 ADD     SP,2                         ; FIX UP THE STACK
  100.                 CMP     AL,1                         ; # OF PARAMETERS = 1 ?
  101.                 JNB     GETTYPE                      ; YES. GET THE TYPE
  102.                 JMP     SHORT FERROR                 ; NO. RETURN ERROR
  103.  
  104. GETTYPE:
  105.                 MOV     AX,1                         ; SPECIFY FIRST PARAM
  106.                 PUSH    AX
  107.                 CALL    __PARINFO                    ; CALL INFO FUNCTION
  108.                 ADD     SP,2                         ; FIX UP THE STACK
  109.                 TEST    AX,2                         ; NUMERIC?
  110.                 JNZ     GETDRIVE                     ; YES.  GET DRIVE
  111.                 JMP     SHORT FERROR                 ; NO.  REPORT ERROR
  112.  
  113. GETDRIVE:
  114.                 MOV     AX,1                         ; GET 1ST PARAMETER (drive)
  115.                 push    ax                           ;
  116.                 call    __parni                      ; must be a integer type
  117.                 add     sp,2                         ; fix up the stack
  118.                 push    ax                           ; save drive
  119.                 int     11h                          ; get equipment list
  120.                 mov     ah,0                         ; clear high byte
  121.                 mov     cl,6                         ; set shift count
  122.                 shr     al,cl                        ; shift diskette count
  123.                 pop     bx                           ; restore drive
  124.                 cmp     bl,al                        ; does drive exist?
  125.                 jbe     ParamOk                      ; yes, so continue
  126. derror:         jmp     short Ferror                 ; Invalid drive
  127.  
  128. ParamOk:
  129.                 push    ds                           ; Save DS
  130.                 mov     dx,_FT_DATASEG               ; DATA SEGMENT
  131.                 MOV     DS,DX                        ; IN DS REGISTER
  132.                 MOV     ES,DX                        ; IN ES REGISTER
  133.                 MOV     FDRIVE,BL                    ; SAVE DRIVE NUMBER
  134.                 XOR     AX,AX                        ; RESET DISKETTE SYSTEM
  135.                 INT     13H                          ; CALL BIOS
  136.                 CALL    _FTFLOPT                     ; TEST DISKETTE TYPE
  137.                 POP     DS                           ; RESTORE DS
  138.                 JMP     SHORT EXIT                   ; RETURN
  139.  
  140. FERROR:
  141.                 MOV     AX,-1                        ; BAD PARAMETERS
  142.  
  143. EXIT:
  144.                 PUSH     AX                          ; PUSH RETURN VALUE
  145.                 CALL     __RETNI                     ; AND RETURN IT TO CLIPPER
  146.                 ADD      SP,2                        ; FIX UP THE STACK
  147.  
  148.                 RET                                  ; FAR RETURN TO CLIPPER
  149.  
  150. FT_FLOPTST      ENDP
  151.  
  152. ;-----------------------------------------------------------;
  153. ; LOCAL SUBROUTINE - CALL BIOS INT 13 FOR READ SECTOR       ;
  154. ;-----------------------------------------------------------;
  155.  
  156. _FTINT13        PROC    NEAR
  157.                 PUSH    BX                           ; SAVE REGS
  158.                 PUSH    ES                           ;
  159.                 PUSH    AX                           ;
  160.                 INT     13H                          ; CALL BIOS (read sector)
  161.                 jnc     ftIntRet                     ; Read ok. Exit
  162.                 xor     ax,ax                        ; reset diskette system
  163.                 int     13h                          ; call BIOS
  164.                 pop     ax                           ; restore regs
  165.                 pop     es                           ; for retry
  166.                 push    es                           ; save regs
  167.                 push    ax                           ;
  168.                 int     13h                          ; call BIOS (read sector)
  169.                 jnc     ftIntRet                     ; Read ok. Exit
  170.                 xor     ax,ax                        ; reset diskette system
  171.                 int     13h                          ; call BIOS
  172.                 pop     ax                           ; restore regs
  173.                 pop     es                           ; for retry
  174.                 push    es                           ; save regs
  175.                 push    ax                           ;
  176.                 int     13h                          ; call BIOS (read sector)
  177. ftIntRet:       pop     bx                           ; restore regs
  178.                 pop     es                           ;
  179.                 pop     bx                           ;
  180.                 ret                                  ; near return
  181.  
  182. _ftint13        endp
  183.  
  184. ;-----------------------------------------------------------;
  185. ; Local subroutine - check boot sector                      ;
  186. ;-----------------------------------------------------------;
  187.  
  188. _ftflopt        proc    near
  189.  
  190.                 push    di                           ; preserve
  191.                 mov     di,OFFSET _FT_DataSeg:boot_sect   ; address of buffer
  192. ftflopred:
  193.                 xor     dx,dx                        ; c